﻿using System;

namespace Common
{
    public class VueLog
    {
        private static Message Msg(string message, string type, object data = null, Guid? id = null, DateTime? time = null, bool flush = false, int countdown = 0)
        {
            return new Message
            {
                message = message,
                type = type,
                id = id ?? Guid.NewGuid(),
                time = (time ?? DateTime.Now).ToString("HH:mm:ss"),
                flush = flush,
                countdown = countdown,
                data = data,
            };
        }

        public static Message Info(string message, object data = null, int countdown = 0) => Msg(message, "info", data, countdown: countdown);
        public static Message Success(string message, object data = null, int countdown = 0) => Msg(message, "success", data, countdown: countdown);
        public static Message Failed(string message, object data = null, int countdown = 0) => Msg(message, "failed", data, countdown: countdown);
        public static Message Warning(string message, object data = null, int countdown = 0) => Msg(message, "warning", data, countdown: countdown);

        public static Message FlushInfo(Guid id, string message, object data = null) => Msg(message, "info", data, id, flush: true);
        public static Message FlushSuccess(Guid id, string message, object data = null) => Msg(message, "success", data, id, flush: true);
        public static Message FlushFailed(Guid id, string message, object data = null) => Msg(message, "failed", data, id, flush: true);
        public static Message FlushWarning(Guid id, string message, object data = null) => Msg(message, "warning", data, id, flush: true);
    }

    public class Message
    {
        public Guid id { get; set; } = Guid.NewGuid();
        public string message { get; set; }
        public string type { get; set; }
        public string time { get; set; }
        public bool flush { get; set; }
        public int countdown { get; set; }
        public object data { get; set; }
    }
}
